<template>
  <div>
    <div><button @click="isShow = !isShow">显示/隐藏</button></div>
    <transition name="why" @enter="enter" @leave="leave" :css="false">
      <!-- 添加:css='false'可以让vue跳过css的检测，因为这里用不到css动画，所以跳过 -->
      <h2 class="title" v-if="isShow">Hello World</h2>
    </transition>
  </div>
</template>

<script>
import gsap from "gsap";
export default {
  name: "App",
  data() {
    return {
      isShow: true,
    };
  },
  methods: {
    enter(el, done) {
      // console.log(el);
      // console.log(done);
      gsap.from(".title", {
        scale: 0,
        x: 200,
        onComplete: done,
      });
      // 或者
      // gsap.from(el, {
      //   scale: 0,
      //   x: 200,
      // });
    },
    leave(el, done) {
      gsap.to(".title", {
        scale: 0,
        x: 200,
        onComplete: done,
      });
      // gsap.to(el, {
      //   scale: 0,
      //   x: 200,
      //   onComplete: done,
      // });
    },
  },
};
</script>

<style lang="less">
.title {
  display: inline-block;
}
</style>
